using System;
using System.Collections;
using System.Web;

namespace app.scrum
{
    public partial class Team : ScrumPage
    {

        public Team()
        {
            this.sObject.tableName = ScrumObject.objectName_Team;
        }

        public override void read(HttpContext context)
        {
            this.sObject.readCmdText = "select t.* from " + this.sObject.tableName
                + " t, " + ScrumObject.objectName_Product + " p where t.product__c = p.id__c";
            try
            {
                ArrayList sObjList = this.sObject.read();
                ScrumObjectHelper.assignLookup(this.sObject, sObjList, ScrumObject.objectName_Product);
                string json = JsonHelper.getJson(sObjList);
               context.Response.Write(json);
            }
            catch (Exception ex)
            {
                this.handleException(context.Response, ex);
            }
        }

        public override void create(HttpContext context, ArrayList sObjList)
        {
            try
            {
                int num = 0;
                long maxId = 0;
                foreach (ScrumObject sObj in sObjList)
                {
                    if (maxId == 0)
                    {
                        maxId = this.sObject.getMaxId();
                    }
                    maxId++;
                    ScrumField id = new ScrumField();
                    id.name = ScrumField.fieldName_Id;
                    id.value = maxId;
                    sObj.addField(sObj, id);
                    this.sObject.genCreateCmdText(sObj);
                    ScrumField startDate = (ScrumField)sObj.fieldMap[ScrumField.fieldName_StartDate];
                    num += this.sObject.create(sObj);

                }
                context.Response.Write(num);
            }
            catch (Exception ex)
            {
                this.handleException(context.Response, ex);
            }
        }

        public override void update(HttpContext context, ArrayList sObjList)
        {
            try
            {
                base.update(context, sObjList);
                int num = 0;
                foreach (ScrumObject sObj in sObjList)
                {
                    num += this.sObject.update(sObj);
                }
                context.Response.Write(num);
            }
            catch (Exception ex)
            {
                this.handleException(context.Response, ex);
            }
        }
    }
}